﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Crgd.UAuthServer.Application.Utils
{
    public static class PathUtil
    {
        public static string Join(params string[] parts)
        {
            if (parts.Length == 0) throw new InvalidOperationException("至少需要1个参数");
            var path = parts[0];
            if (!path.StartsWith('/'))
            {
                path = "/" + path;
            }
            if (parts.Length == 1)
            {
                return path;
            }
            for (var i = 1; i < parts.Length; i++)
            {
                var part = parts[i];
                if (part.StartsWith('/') && path.EndsWith('/'))
                {
                    path += part.Substring(1);
                }
                else if (!part.StartsWith('/') && path.EndsWith('/'))
                {
                    path += part;
                }
                else if (!path.StartsWith('/') && !path.EndsWith('/'))
                {
                    path += '/' + part;
                }
                else
                {
                    path += part;
                }
            }
            return path;
        }
    }
}
